<template>
  <div class="close-order">
    <el-radio-group v-model="radio">
      <el-radio :label="item.dictId" v-for="item,index in dictionaries.order_main_close_reason" :key="index">{{ item.dictName }}</el-radio>
    </el-radio-group>
  </div>
</template>

<script>
export default {
  name: 'closeOrder',
  props: {
    type: {
      type: String,
      default: 'closeOrder'
    },
    afterId: {
      type: String,
      default: ''
    },
    orderObj: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      dictionaries: { // 字典数据
        order_main_close_reason: [] // 关闭原因
      },
      radio: 1,
      radioArr: [
        { label: '客户暂时不需要了', value: 1 },
        { label: '信息填写错误重新拍', value: 2 },
        { label: '商品缺货', value: 3 },
        { label: '其他原因', value: 4 }
      ]
    }
  },
  computed: {
    customClass () {}
  },
  created () {
    // this.type === 'fullscreen' && (this.fullscreen = true)

    this.getCommWarehouse()
    // 获取字典值
    for (const type in this.dictionaries) { this.getDictionaries(type) }
  },
  methods: {
    // 获取字典数据
    getDictionaries (type) {
      if (type && this.dictionaries[type].length > 0) { return }
      const params = { groupId: type }
      this.$api.dictionaries(params).then((res) => {
		  console.log(res)
        this.dictionaries[type] = res.data
		console.log(this.dictionaries)
      }).catch((err) => {
        console.log(err)
      })
    },
    getCommWarehouse () {
      const params = { pageNo: 1, pageSize: 10000 }
      this.$api.commWarehouse(params).then((res) => {
        this.commWarehouseList = res.data.list
      }).catch((err) => {
        console.log(err)
      })
    },
    submit () {
      this.$refs['ruleModifyOrderNoForm'].validate((valid) => {
        if (valid) {
          const params = Object.assign({}, this.ruleModifyOrderNoForm)
          params.typeFlag = this.type === 'modifyOrderNoOne' ? 1 : 2 // 类型（1退货；2换货）
          if (JSON.stringify(this.orderObj) !== '{}') { params.afterId = this.orderObj.id }
          if (this.afterId) { params.afterId = this.afterId }
          params.logisticsNumber = params.logisticsNumber.trim()
          this.$api.afterUpdateLogistics(params).then((res) => {
            this.$refs['ruleModifyOrderNoForm'].resetFields()
            this.$emit('submitState', true, params.typeFlag)
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
          }).catch((err) => {
            this.$emit('submitState', false)
            console.log(err)
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
.close-order{
  .el-radio-group{
.el-radio{
  display: block;
  margin: 15px;
}
  }
}

</style>

